<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class AdRequest extends Request
{

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        $data = Request::all();
        if (isset($data['id'])) {
            $rules['id'] = 'required|numeric';
        }
        $rules['title'] = 'required';
        $rules['type'] = 'required';
        $rules['link_url'] = 'required|url';
        $rules['image'] = 'required';
        $rules['intro'] = 'required';
        if (!empty($data['click_count'])) {
            $rules['click_count'] = 'numeric';
        }
//        $rules['start_time'] = 'required|date';
//        $rules['expired_time'] = 'required|date';
        $rules['bg_image'] = 'required';
        if (!empty($data['sort'])) {
            $rules['sort'] = 'numeric';
        }
        $rules['status'] = 'required|numeric';

        return array();
//        return $rules;
    }

    public function attributes()
    {
        $attributes = array(
            'id'           => '广告id',
            'title'        => '广告名称',
            'type'         => '广告类型',
            'link_url'     => '链接地址',
            'image'        => '图片地址',
            'intro'        => '广告描述',
            'click_count'  => '点击数',
            'start_time'   => '开始时间',
            'expired_time' => '过期时间',
            'bg_image'     => '背景图片',
            'sort'         => '排序',
            'status'       => '状态',
        );

        return array();
//        return $attributes;
    }

    public function messages()
    {
        $messages = [
            'required' => ':attribute为必填选项',
            'numeric'  => ':attribute必须为数字',
            'url'      => ':attribute必须为合乎规范的url地址',
            'date'     => ':attribute必须为日期',
        ];

        return $messages;
    }
}
